package com.example.mobile2021606129ly0506;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText edMainTitle;
    private Button butNavi;
    private Button butPhone;
    private Button butMap;
    private Button butPhoto;

    private Intent intent;
    private String input;
    private Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        edMainTitle = (EditText) findViewById(R.id.ed_main_title);
        butNavi = (Button) findViewById(R.id.but_navi);
        butPhone = (Button) findViewById(R.id.but_phone);
        butMap = (Button) findViewById(R.id.but_map);
        butPhoto = (Button) findViewById(R.id.but_photo);
        butNavi.setOnClickListener(this);
        butPhone.setOnClickListener(this);
        butMap.setOnClickListener(this);
        butPhoto.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.but_navi:
                input=edMainTitle.getText().toString().trim();
                uri=Uri.parse(input);
                intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;


            case R.id.but_phone:
                input=edMainTitle.getText().toString().trim();
                uri=Uri.parse(input);
                intent = new Intent(Intent.ACTION_DIAL,uri);
                startActivity(intent);
                break;


            case R.id.but_map:
                input=edMainTitle.getText().toString().trim();
                uri=Uri.parse("geo:"+input);
                intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;

            case R.id.but_photo:
                intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivity(intent);
                break;

        }
    }
}